// setting limit for text area
function charCounter(field, countField, limit){
   if( field.value.length > limit){
	field.value = field.value.substring(0, limit);   
   } else {
	  countField.value = limit - field.value.length;   
   }
}

 function validateFields(form){
	var fieldsValid = true;
	var title = document.getElementById('title');
	var author = document.getElementById('author');
	var isbn = document.getElementById('isbn');
	var dollars = document.getElementById('dollars');
	var cents = document.getElementById('cents');


	if (cents.value.length < 2) {
		cents.value = "";
		 fieldsValid = false;
	}

	//fields to check if they are empty
	var checkEmpty = new Array();
	checkEmpty.push(title);
    checkEmpty.push(author);
	checkEmpty.push(isbn);
	checkEmpty.push(dollars);
	// check array, to put login for all fields in one place
	for(i = 0; i < checkEmpty.length; i++ ){
		// what to do if its empty
		if (checkEmpty[i].value==""){
		   // any bad field breaks submit
		   fieldsValid = false;
	var foundElement = document.getElementById(checkEmpty[i].id+"Error");
			   if (foundElement!= null){
				 document.getElementById(checkEmpty[i].id+"Error").style.display = "inline";  
			  }
			} else {
				 var foundElement = document.getElementById(checkEmpty[i].id+"Error");
			   if (foundElement!= null){
				 document.getElementById(checkEmpty[i].id+"Error").style.display = "none";  
			  }
		}
	}
	
	if (cents.value.length < 2) {
		 fieldsValid = false;
		  document.getElementById("dollarsError").style.display = "inline"; 
	}

	return fieldsValid;


 }